package net.oschina.app.ui;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.FragmentManager;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;

import net.oschina.app.R;
import net.oschina.app.viewpagerfragment.MyFragment.BaseViewPagerAdapter;

/**
 * Created by Administrator on 2017/4/5.
 */

public class CollectionActivity extends AppCompatActivity{

    private Toolbar mToolbar;
    private TabLayout mTabLayout;
    private ViewPager mViewPager;
    private String[] mArr;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_collection);
        mToolbar = (Toolbar) findViewById(R.id.tb_my_collection);
        setSupportActionBar(mToolbar);
        mToolbar.setNavigationIcon(R.drawable.actionbar_back_icon_normal);
        mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        mTabLayout = (TabLayout) findViewById(R.id.base_tab);
        mViewPager = (ViewPager) findViewById(R.id.base_vp);

        CollectionAdapter collectionAdapter = new CollectionAdapter(getSupportFragmentManager(), R.layout.item_fragment);
        mViewPager.setAdapter(collectionAdapter);
        //设置tablayout与viewpager 关联
        mTabLayout.setupWithViewPager(mViewPager);

    }

    class CollectionAdapter extends BaseViewPagerAdapter{

        public CollectionAdapter(FragmentManager fm, int layout) {
            super(fm, R.array.collection_item);
            mArr = new String[]{"软件","话题","代码","博客","资讯"};
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return mArr[position];
        }
    }
}
